import { h } from 'vue'
import { IconSearch } from '@arco-design/web-vue/es/icon'
const align = 'left'
export const getColumns = (config: any = {}) => {
  const sortColumns = localStorage.getItem('tableSort')
  let columns = [
    {
      title: '物品名称',
      dataIndex: 'item_name',
      // width: 100,
      filterable: {
        filter: (value: string, record: anyObj) =>
          config.filter(value, record, 'item_name'),
        slotName: 'name-filter',
        icon: () => h(IconSearch),
      },
      align,
    },
    {
      title: '属性',
      dataIndex: 'itemDesc',
      width: 180,
      slotName: 'itemDesc',
      align,
    },
    {
      title: '异色',
      width: 80,
      dataIndex: 'isShiny',
      slotName: 'isShiny',
      filterable: {
        filter: (value: string, record: anyObj) =>
          config.filter(value, record, 'isShiny'),
        slotName: 'name-filter',
        icon: () => h(IconSearch),
      },
      align,
    },
    {
      title: '总价',
      dataIndex: 'total_price',
      slotName: 'total_price',
      sortable: {
        sortDirections: ['ascend', 'descend'],
        sorter: true,
      },
      align,
    },
    {
      title: '买家',
      dataIndex: 'buyer_account',
      filterable: {
        filter: (value: string, record: anyObj) =>
          config.filter(value, record, 'buyer_account'),
        slotName: 'name-filter',
        icon: () => h(IconSearch),
      },
      slotName: 'buyer_account',
      align,
    },
    {
      title: '卖家',
      dataIndex: 'seller_account',
      filterable: {
        filter: (value: string, record: anyObj) =>
          config.filter(value, record, 'seller_account'),
        slotName: 'name-filter',
        icon: () => h(IconSearch),
      },
      align,
    },
    {
      title: '单价',
      dataIndex: 'unit_price',
      // width: 100,
      sortable: {
        sortDirections: ['ascend', 'descend'],
        sorter: true,
      },
      align,
    },
    {
      title: '数量',
      dataIndex: 'quantity',
      width: 90,
      sortable: {
        sortDirections: ['ascend', 'descend'],
        sorter: true,
      },
      align,
    },
    {
      title: '创建时间',
      dataIndex: 'create_time',
      width: 110,
      slotName: 'create_time',
      align,
    },
    // 学习力
    {
      title: '学习力',
      dataIndex: 'learning_power',
      slotName: 'learning_power',
      width: 180,
      align,
    },
    {
      title: '买家-游戏内余额',
      dataIndex: 'game_balance',
      sortable: {
        sortDirections: ['ascend', 'descend'],
        sorter: true,
      },
      // width: 100,
    },
    {
      title: '买家-交易行余额',
      dataIndex: 'trade_balance',
      sortable: {
        sortDirections: ['ascend', 'descend'],
        sorter: true,
      },
      // width: 100,
    },
    {
      order_id: '订单号',
      title: '订单号',
      dataIndex: 'order_id',
      // width: 180,
      filterable: {
        filter: (value: string, record: anyObj) =>
          config.filter(value, record, 'order_id'),
        slotName: 'name-filter',
        icon: () => h(IconSearch),
      },
      align,
    },
  ]
  if (sortColumns && !config.originColumns) {
    const sortColumnsList = JSON.parse(sortColumns)
    // 根据sortColumnsList的dataIndex排序
    let arr: any[] = []
    sortColumnsList.forEach((item: any) => {
      const column = columns.find(
        (column) => column.dataIndex === item.dataIndex
      )
      if (column) {
        arr.push(column)
      }
    })
    columns = arr
  }
  return columns
}
